<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${packageName}.dao.${model.firstUpperCaseName}Dao" >
<#--    <resultMap id="BaseResultMap" type="${packageName}.vo.${model.firstUpperCaseName}" >
        <#list model.fieldList as field>
            <#if field.pk>
        <id column="${field.originalName}" property="${field.firstLowerCaseName}" jdbcType="${field.columnType}" />
                <#else >
        <result column="${field.originalName}" property="${field.firstLowerCaseName}" jdbcType="${field.columnType}" />
            </#if>
        </#list>
    </resultMap>-->
    <select id="selectList" parameterType="${packageName}.dto.${model.firstUpperCaseName}Dto" resultType="${packageName}.vo.${model.firstUpperCaseName}">
        select
        <#list model.fieldList as field>
            <#if field.originalName == field.firstLowerCaseName>
                <#if field.columnType == 'DATETIME'>
            DATE_FORMAT(${field.originalName}, '%Y-%m-%d %H:%i:%s') as ${field.firstLowerCaseName}<#if field_has_next>,</#if>
                <#else >
            ${field.originalName}<#if field_has_next>,</#if>
                </#if>
            <#else >
                <#if field.columnType == 'DATETIME'>
            DATE_FORMAT(${field.originalName}, '%Y-%m-%d %H:%i:%s') as ${field.firstLowerCaseName}<#if field_has_next>,</#if>
                <#else >
            ${field.originalName} as ${field.firstLowerCaseName}<#if field_has_next>,</#if>
                </#if>
            </#if>
        </#list>
        from
            ${model.originalName}
        <where>
        <#list model.fieldList as field>
            <#if field.logicDelete>
            ${field.originalName} != 0
            </#if>
        </#list>
        </where>
    </select>

    <insert id="insert" parameterType="${packageName}.dto.${model.firstUpperCaseName}Dto">
        insert
        into
        ${model.originalName} (
        <#list model.fieldList as field>
            <#if !field.pk>
            ${field.originalName}<#if field_has_next>,</#if>
            </#if>
        </#list>
            )
        values(
        <#list model.fieldList as field>
        <#if !field.pk>
            <#if field.logicDelete>
            0<#if field_has_next>,</#if>
            <#else >
            <#noparse>#{</#noparse>${field.firstLowerCaseName}}<#if field_has_next>,</#if>
            </#if>
        </#if>
        </#list>
        )
    </insert>

    <update id="deleteById" parameterType="${packageName}.dto.${model.firstUpperCaseName}Dto">
        update
            ${model.originalName}
        set
        <#list model.fieldList as field>
            <#if field.updateFill>
            ${field.originalName} = <#noparse>#{</#noparse>${field.firstLowerCaseName}}<#if field_has_next>,</#if>
            </#if>
            <#if field.logicDelete>
            ${field.originalName} = 1<#if field_has_next>,</#if>
            </#if>
        </#list>
        <where>
        <#list model.fieldList as field>
            <#if field.pk>
            ${field.originalName} = <#noparse>#{</#noparse>${field.firstLowerCaseName}}
            </#if>
        </#list>
        </where>
    </update>

    <update id="updateById" parameterType="${packageName}.dto.${model.firstUpperCaseName}Dto">
        update
            ${model.originalName}
        set
        <#list model.fieldList as field>
            <#if !field.pk>
            <if test="${field.firstLowerCaseName} != null and ${field.firstLowerCaseName} != ''">
            ${field.originalName} = <#noparse>#{</#noparse>${field.firstLowerCaseName}}<#if field_has_next>,</#if>
            </if>
            </#if>
        </#list>
        <where>
        <#list model.fieldList as field>
            <#if field.pk>
            ${field.originalName} = <#noparse>#{</#noparse>${field.firstLowerCaseName}}
            </#if>
        </#list>
        </where>
    </update>

    <select id="getById" parameterType="${packageName}.dto.${model.firstUpperCaseName}Dto" resultType="${packageName}.vo.${model.firstUpperCaseName}">
        select
        <#list model.fieldList as field>
            <#if field.originalName == field.firstLowerCaseName>
                <#if field.columnType == 'DATETIME'>
            DATE_FORMAT(${field.originalName}, '%Y-%m-%d %H:%i:%s') as ${field.firstLowerCaseName}<#if field_has_next>,</#if>
                <#else >
            ${field.originalName}<#if field_has_next>,</#if>
                </#if>
            <#else >
                <#if field.columnType == 'DATETIME'>
            DATE_FORMAT(${field.originalName}, '%Y-%m-%d %H:%i:%s') as ${field.firstLowerCaseName}<#if field_has_next>,</#if>
                <#else >
            ${field.originalName} as ${field.firstLowerCaseName}<#if field_has_next>,</#if>
                </#if>
            </#if>
        </#list>
        from
             ${model.originalName}
        <where>
        <#list model.fieldList as field>
            <#if field.logicDelete>
            and ${field.originalName} != 0
            </#if>
            <#if field.pk>
            and ${field.originalName} = <#noparse>#{</#noparse>${field.firstLowerCaseName}}
            </#if>
        </#list>
        </where>
    </select>
</mapper>